import { message, notification, Modal } from 'ant-design-vue'
import { SmileOutlined, ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { h, createVNode } from 'vue'
message.config({
  duration: 2,
  maxCount: 3,
  getContainer: () => document.body
})
interface remindInterFace {
    title: string;
    content: string | any;
    submitCallBack?: any;
    icon?: any,
    cleanCallBack?: any;
    cancelText?:string;
    okText?:string;
    cancelButtonProps?:any;
    okButtonProps?:any;
}
export default {
  // 顶部成功提示
  successMsg (msg: string, config?: any) {
    if (config) {
      message.config({
        ...config
      })
    }
    message.success(msg)
  },
  // 顶部失败提示
  errorMsg (msg: string, config?: any) {
    if (config) {
      message.config({
        ...config
      })
    }
    message.error(msg)
  },
  // 右上角提示
  notificationMsg (msg: string, callBack?: any, icon: string | any = '') {
    notification.open({
      message: '消息提示',
      description: msg,
      icon: icon === '' ? h(icon || SmileOutlined, { style: 'color: #108ee9' }) : icon,
      onClick: () => {
        callBack && callBack()
      }
    })
  },
  // 带确定和取消提示
  remindConfirm (type: string, msgData: remindInterFace) {
    const isString = (typeof msgData.content === 'string') && msgData.content.constructor === String
    Modal[type]({
      title: msgData.title,
      icon: msgData.icon ? msgData.icon : createVNode(ExclamationCircleOutlined),
      content: isString ? createVNode('div', { style: '' }, msgData.content) : msgData.content,
      okText: () => msgData.okText ? msgData.okText : '确定',
      cancelText: () => msgData.cancelText ? msgData.okText : '取消',
      cancelButtonProps: msgData.cancelButtonProps ? msgData.cancelButtonProps : null,
      okButtonProps: msgData.okButtonProps ? msgData.okButtonProps : null,
      onOk () {
        msgData.submitCallBack && msgData.submitCallBack()
      }
    })
  },
  // 带确定和取消提示
  remindMsg (msgData: remindInterFace) {
    const isString = (typeof msgData.content === 'string') && msgData.content.constructor === String
    Modal.confirm({
      title: () => msgData.title,
      icon: () => msgData.icon ? msgData.icon : createVNode(ExclamationCircleOutlined),
      content: () => isString ? createVNode('div', { style: 'color:red;' }, msgData.content) : msgData.content,
      okText: () => msgData.okText ? msgData.okText : '确定',
      cancelText: () => msgData.cancelText ? msgData.cancelText : '取消',
      cancelButtonProps: msgData.cancelButtonProps ? msgData.cancelButtonProps : null,
      okButtonProps: msgData.okButtonProps ? msgData.okButtonProps : null,
      onOk: () => {
        msgData.submitCallBack && msgData.submitCallBack()
      },
      onCancel () {
        msgData.cleanCallBack && msgData.cleanCallBack()
      },
      class: 'test'
    })
  }
}
